--钙质化
local gaizhihua = fk.CreateSkill {
    name = "mcdh_gaizhihua",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

gaizhihua:addEffect(fk.TargetSpecifying,{
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) or player:getMark("mcdh_charge") < 2 then return false end
        return data.card.is_damage_card and data.firstTarget
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = data:getAllTargets()
        table.insertIfNeed(targets, data.from)
        local players = 
            room:askToChoosePlayers(player, {
              targets = targets,
              min_num = 1,
              max_num = 1,
              prompt = "#mcdh_gaizhihua-choice",
              skill_name =self.name,
              cancelable = true
            })
          
        if #players > 0 then
            self.cost_data = players[1]
            lib.mcdh_charge(player, -2)
            return true
        end
        return false
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local target = self.cost_data
        if self.cost_data == data.from then
            room:addPlayerMark(target, "@@mcdh_gaizhihua_1-turn", 1)
        else
            room:addPlayerMark(target, "@@mcdh_gaizhihua_2-turn", 1)
        end
    end
})

gaizhihua:addEffect( fk.DamageInflicted,{
    can_trigger = function(self, event, target, player, data)
        return target == player and target:getMark("@@mcdh_gaizhihua_2-turn") > 0
                and (data.damageType == fk.FireDamage or data.damageType == fk.NormalDamage)
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        if data.damageType == fk.FireDamage then
            data.damage = data.damage + player:getMark("@@mcdh_gaizhihua_2-turn")
        else
            return true
        end
    end,
})

gaizhihua:addEffect(fk.TargetSpecified,{
    can_refresh = function(self, event, target, player, data)
        return data.from == player and player:getMark("@@mcdh_gaizhihua_1-turn") > 0
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local to = data.to
        data.to:addQinggangTag(data)
    end
})

Fk:loadTranslationTable {
    ["mcdh_gaizhihua"] = "钙质化",
    [":mcdh_gaizhihua"] = "『钙质化』<br>蓄力技(2)。当一名角色使用伤害牌指定目标时，你可以令其本回合使用牌无视防具，或令除其以外的一个目标本回合获得如下效果：<br>1.受到无属性伤害时，防止之；<br>2.受到火焰伤害时，伤害值+1。",
    ["#mcdh_gaizhihua-choice"] = "钙质化：选择使用者或一个目标",
    ["@@mcdh_gaizhihua_1-turn"] = "钙质化-青釭剑",
    ["@@mcdh_gaizhihua_2-turn"] = "钙质化-藤甲",
}

return gaizhihua